<?php
namespace app\shell;
use share\console\CConsole;
use share\console\CLIRunner;
use share\service\SmsLimitService;
use share\service\SoftAccessService;

class CSoftAccess extends CLIRunner{

    /**
     * 添加访问记录并检查
     */
    public static function add_and_check_action($ip='127.0.0.1',$phone = '17688794855',$sence = SoftAccessService::SOFT_ACCESS_SCENE_RESET_PASS){
        // $smsLimit = SmsLimitService::instance($phone, $ip); 
        // $smsLimitRet = $smsLimit->check();
        // CConsole::print_line("smsLimit check result is ".($smsLimitRet ? "pass" : "forbidden"));
        // if($smsLimitRet){
        //     $smsLimit->addRecord(); 
        // }
               
        $softAccessService =  SoftAccessService::instance($ip, $sence);
        
        $softAccessRet = $softAccessService->isNeedAuth();
        CConsole::print_line("softAccess isNeedAuth result is ".($softAccessRet ? "forbidden" : "pass"));
        // $softAccessService->check("123456");

        // $token = SoftAccessService::auth($ip, $sence);

        $token = "f6b00a2c4258168e12b69d3905684cfc9d90cfc37c440d700e645eed";//f6b00a2c4258168e12b69d3905684cfc9d90cfc37c440d700e645eed

        var_dump("token",$token);


        $ret = $softAccessService->check($token);
        CConsole::print_line("softAccess check result is ".($ret ? "pass" : "forbidden"));

        $softAccessService->addVisitTimes();
    
    }

    public static function allow_action($ip='127.0.0.1',$phone = '17688794855'){
        SoftAccessService::allow($ip);

        SmsLimitService::allow($phone,$ip); 
    }

}